package com.example.demo.thread;

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;

public class ThreadTest3 implements Callable<Integer> {

    @Override
    public Integer call() throws Exception {
        System.out.println("线程名称" + Thread.currentThread().getName());
        int sum = 0;
        for (int i = 1; i <= 10; i++) {
            sum += i;
        }
        return sum;
    }

    public static void main(String[] args) throws Exception {
        System.out.println("线程名称" + Thread.currentThread().getName());
        ThreadTest3 callable = new ThreadTest3();
        FutureTask<Integer> futureTask = new FutureTask<>(callable);
        Thread thread = new Thread(futureTask);
        thread.start();
        Integer result = futureTask.get();
        System.out.println("计算结果：" + result);
    }
}
